﻿using System;
using System.Collections.Generic;
using System.Web;
using BackstageMusiciansFriend;
using DBMethodsNamespace;
using ControlLogNamespace;


namespace ControlSesionNamespace
{

    /// <summary>
    /// Summary description for ControlSesion
    /// </summary>
    public class ControlSesion
    {
        public const string UsuarioLogin = "UsuarioLogin";
        public const string AccessToken = "access_token";

        public static void session(string strKey, string strValue)
        {
            try
            {
                DBMethods objConnection = new DBMethods();
                if (!objConnection.existeValorSesion(strKey))
                {
           //         ControlLog.writeLog("[session] no existe el valor ,agrego");                                     
                    objConnection.agregarValorSesion(strKey, strValue);                    
                }
                else
                {
            //        ControlLog.writeLog("[session]  existe el valor ,actualizo");                                     
                    objConnection.actualizarValorSesion(strKey, strValue);
                }
            }
            catch(Exception ex)
            {
                ControlLog.writeLog("[session] Excepcion agregando/actualizando valor de sesion (" + strKey + "," + strValue + ") "+ex.Message);
                throw ex;
            }
        }
        public static string session(string strKey)
        {
            string strValue = "";
            try
            {
                DBMethods objConnection = new DBMethods();
                if (objConnection.existeValorSesion(strKey))
                {
               //     ControlLog.writeLog("[session] existe el valor = " + strKey);                                     
                    strValue = objConnection.obtenerValorSesion(strKey);
                }
                else
                {
              //      ControlLog.writeLog("[session] no existe el valor =" + strKey);                                         
                    strValue = "";
                }
            }
            catch (Exception ex)
            {
                ControlLog.writeLog("[session] Excepcion obteniendo valor de sesion (" + strKey + ") " + ex.Message);
                throw ex;
            }
            return strValue;
        }


        public static void borrar(string strKey)
        {
             
            try
            {
                DBMethods objConnection = new DBMethods();
                objConnection.borrarValorSesion(strKey);
                
            }
            catch (Exception ex)
            {
                ControlLog.writeLog("[ControlSesion:borrar] Excepcion eliminando valor de sesion (" + strKey + ") " + ex.Message);
                throw ex;
            }
            
        }
    }
}